#include <wx/wx.h>
#include <wx/filename.h>
#include <wx/stdpaths.h>
#include "cfgmgr.h"

ConfigManager::ConfigManager() : wxFileConfig(_T("Daodict"), _T("Victsoft"), _T(".Daodict.conf")), \
APP_VERSION_MAJOR(0), APP_VERSION_MINOR(1), APP_VERSION_REVISION(0), \
app_version_string(wxString(_T("0.1.0"))), app_name(wxString(_T("Daodict"))), \
app_author(wxString(_T("Brant Young"))), \
app_website(wxString(_T("http://www.daodict.com/dict"))), \
app_email(wxString(_T("brant.young@gmail.com"))), \
app_description(wxString(_("Daodict is an open source,multi-platform and \
multi-language computer dictionary, provide large number of dictionaries.")))
{
	wxLogMessage(_T("ConfigManager::ConfigManager"));
	
    if(wxTheApp!=NULL) {
        wxTheApp->SetAppName(app_name); // !important!
    }

    this->_init_paths();
}

void ConfigManager::_init_paths() {
    wxStandardPathsBase& std_paths = wxStandardPaths::Get();

    
    #ifdef __WXGTK__ // set unix install prefix
    	wxFileName exedir_fn(std_paths.GetExecutablePath(), wxEmptyString);
    	exedir_fn.RemoveLastDir();
	    std_paths.SetInstallPrefix(exedir_fn.GetPath);
	#endif
	
    // init Global Resources Directory
    global_res_dir = wxFileName(std_paths.GetResourcesDir(), wxEmptyString);

    // init Global Data Directory
    global_data_dir = wxFileName(std_paths.GetDataDir(), wxEmptyString);
    
    
    // init User Data Directory
    user_data_dir = wxFileName(std_paths.GetUserDataDir(), wxEmptyString);
    user_data_dir.Mkdir(0777, wxPATH_MKDIR_FULL);
}

ConfigManager* ConfigManager::_cfg_mgr = NULL;

